package OJ;

public class Solution {
    //Z字形变换
    public String convert(String s, int numRows) {
        if (s.length() <= numRows || numRows == 1) {
            return s;
        }
        StringBuilder[] arrs = new StringBuilder[numRows];
        for (int i = 0;i < numRows;i++) {
            arrs[i] = new StringBuilder();
        }
        int index = 0;
        boolean circulation = false;
        for (char num : s.toCharArray()) {
            arrs[index].append(num);
            if (index == 0 || index == numRows - 1) {
                circulation = !circulation;
            }
            index += circulation ? 1 : -1;
        }
        StringBuilder result = new StringBuilder();
        for (StringBuilder arr : arrs) {
            result.append(arr);
        }
        return result.toString();
    }
}
